const path = require("path");

module.exports = {
  mode: "universal",
  server: {
    port: 3000, // default: 3000
    host: "0.0.0.0" // default: localhost,
  },
  /*
   ** Headers of the page
   */
  head: {
    title: "实时球赛数据",
    meta: [
      { charset: "utf-8" },
      { name: "viewport", content: "width=device-width, initial-scale=1" },
      {
        hid: "description",
        name: "description",
        content: process.env.npm_package_description || ""
      },
      { name: "referrer", content: "no-referrer" }
    ],
    link: [{ rel: "icon", type: "image/x-icon", href: "/favicon.ico" }]
  },
  /*
   ** Customize the progress-bar color
   */
  loading: { color: "#fff" },
  /*
   ** Global CSS
   */
  css: ["element-ui/lib/theme-chalk/index.css"],

  /*
   ** Plugins to load before mounting the App
   */
  plugins: [
    "@/plugins/element-ui",
    "@/plugins/vue-plyr"
    // { src: "@/plugins/vconsole", ssr: false }
  ],

  /*
   ** Nuxt.js dev-modules
   */
  buildModules: [],
  /*
   ** Nuxt.js modules
   */
  modules: [],
  /*
   ** Build configuration
   */
  build: {
    transpile: [/^element-ui/],
    /*
     ** You can extend webpack config here
     */
    extend(config, ctx) {
      if (ctx.isClient) {
        // 添加 alias 配置
        Object.assign(config.resolve.alias, {
          shared: path.resolve(__dirname, "shared")
        });
      }
      // Run ESLint on save
      const vueLoader = config.module.rules.find(
        loader => loader.loader === "vue-loader"
      );
      /* 把audio标签在编译时转成src属性 */
      vueLoader.options.transformToRequire = {
        audio: "src"
      };
      /* 对mp3等格式的文件用url-loader进行处理 */
      config.module.rules.push({
        test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
        loader: "url-loader",
        options: {
          limit: 10000,
          name:
            process.env.NODE_ENV === "production"
              ? path.posix.join("./", "media/[name].[hash:7].[ext]")
              : path.posix.join("./", "media/[name].[hash:7].[ext]")
        }
      });
    }
  },
  router: {
    middleware: "auth"
  }
};
